<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /**
     * 快速排序：事件复杂度 nlogn ~ n^2
     * 分治法，比基准元素（第一个元素）小的移到左边，大的移到右边 ， 递归
     */
    function quickSort(arr){
      if(arr.length<2){
        return arr
      }
      let index = arr[0]
      let left = arr.filter((v,i) => v<=index && i !== 0)
      let right = arr.filter((v,i) => v>index )
      return [...quickSort(left),index,...quickSort(right)]
    }
    let arr = [3,1,1,4,8,9,7,4,2,0,1,0]
    console.log(quickSort(arr))
  </script>
</body>
</html>